<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<%@ page import="java.util.*,util.*,dal.*,model.*, bll.*"%>
<%
	AgendaModel obj;
	Object temp = request.getAttribute("agenda");
	if (temp != null) {
		try {
			obj = (AgendaModel) temp;
		} catch (Exception ex) {
			obj = new AgendaModel();
		}
	} else {
		obj = new AgendaModel();
	}
%>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Create New Agenda</title>

<link rel="stylesheet" href="css/common.css" />
<link rel="stylesheet" href="css/jquery-ui-1.8.14.custom.css" type="text/css" />
<link rel="stylesheet" href="css/jquery-ui-timepicker.css" type="text/css" />
<link rel="stylesheet" href="css/hyjack.css" type="text/css" />
<link rel="stylesheet" href="css/datepicker.css" />

<script language="javascript" type="text/javascript" src="js/datepicker.js"></script>
<script language="javascript" type="text/javascript" src="js/common.js"></script>
<script language="javascript" type="text/javascript" src="js/jquery.min.js"></script>
<script language="javascript" type="text/javascript" src="js/jquery-1.5.1.min.js"></script>
<script language="javascript" type="text/javascript" src="js/jquery.hyjack.select.js"></script>
<script language="javascript" type="text/javascript" src="js/jquery.ui.core.min.js"></script>
<script language="javascript" type="text/javascript" src="js/jquery.ui.widget.min.js"></script>

<script language="javascript" type="text/javascript" src="js/jquery.ui.timepicker.js"></script>
<script language="javascript" type="text/javascript" src="js/datepicker.js"></script>
<script language="javascript" type="text/javascript" src="js/jquery.hyjack.js"></script>
<script language="javascript" type="text/javascript" src="js/ajaxQuickInsert.js"></script>

<link rel="stylesheet" href="css/inputForm.css" />

<script language="javascript" type="text/javascript">
	var requiredInputs = [['id_event','id_event_required'],['name','name_required'],['code','code_required'],['description','description_required'],['id_author','id_author_required'],['id_approver','id_approver_required'],['start_time','start_time_date_required', 'start_time','start_time_time_required'],['id_venue','id_venue_required'],['status','status_required'],['notification','notification_required']];
	var intInputs = [['id_project','id_project_invalid'],['id_event','id_event_invalid'],['id_author','id_author_invalid'],['id_approver','id_approver_invalid'],['id_venue','id_venue_invalid'],['status','status_invalid'],['notification','notification_invalid']];
	var doubleInputs = [];
	var dateInputs = [['start_time','start_time_date_invalid']];
	var timeInputs = [['start_time','start_time_time_invalid']];

	function checkInputs() {
		var valid = true;

		if (checkRequiredInputs(requiredInputs) == false) {
			valid = false;
		}
		if (checkIntInputs(intInputs) == false) {
			valid = false;
		}
		if (checkDoubleInputs(doubleInputs) == false) {
			valid = false;
		}
		if (checkDateInputs(dateInputs) == false) {
			valid = false;
		}
		if (checkTimeInputs(timeInputs) == false) {
			valid = false;
		}

		// SPECIFIC VALIDATE CODE HERE		

		return valid;
	}
</script>
</head>
<body>
     <%@ include file="menu.jsp"%>
	<br />
    <table>
		<tr>
			<td>
	            <form action="agenda?mode=insert" method="post"
                    onSubmit="return checkInputs()"
                    onreset="return confirm('Do you really want to reset the form?')">
		            <table class="tblInput" border="1">
			            <tr class="inputHeader">
				            <th colspan="3" class="inputHeader">Create New Agenda</th>
			            </tr>
            			<tr class="trField">
				<td class="tdFieldName">Id Project</td>				<td class="tdFieldInput">
                            <select id="id_project" name="id_project" class="hyjack">
									<%=HtmlUtil.genModelSelect(CacheUtil.getProjectList(), null, obj.getIdProject())%>
							</select>
				</td>
				<td class="tdErrMsg">
					<span id="id_project_required" class="errMsg" style="display: none;">Id Project is required</span> 
					<span id="id_project_invalid" class="errMsg" style="display: none;">Id Project is invalid</span>
                    <span id="id_project_error" class="errMsg"><%=obj.errMsgs.IdProject%></span>
                </td></tr>
			<tr class="trField">
				<td class="tdFieldName">Id Event</td>				<td class="tdFieldInput">
                            <select id="id_event" name="id_event" class="hyjack">
									<%=HtmlUtil.genModelSelect(CacheUtil.getEventList(), null, obj.getIdEvent())%>
							</select>
				</td>
				<td class="tdErrMsg">
					<span id="id_event_required" class="errMsg" style="display: none;">Id Event is required</span> 
					<span id="id_event_invalid" class="errMsg" style="display: none;">Id Event is invalid</span>
                    <span id="id_event_error" class="errMsg"><%=obj.errMsgs.IdEvent%></span>
                </td></tr>
			<tr class="trField">
				<td class="tdFieldName">Name</td>			    <td class="tdFieldInput">
					<input class="inputText" type="text" id="name" name="name" maxlength="255" value="<%=obj.getNameToString()%>" />
				</td>
				<td class="tdErrMsg">
					<span id="name_required" class="errMsg" style="display: none;">Name is required</span>
					<span id="name_invalid" class="errMsg" style="display: none;">Name is invalid</span>
                    <span id="name_error" class="errMsg"><%=obj.errMsgs.Name%></span>
				</td></tr>
			<tr class="trField">
				<td class="tdFieldName">Code</td>			    <td class="tdFieldInput">
					<input class="inputText" type="text" id="code" name="code" maxlength="20" value="<%=obj.getCodeToString()%>" />
				</td>
				<td class="tdErrMsg">
					<span id="code_required" class="errMsg" style="display: none;">Code is required</span>
					<span id="code_invalid" class="errMsg" style="display: none;">Code is invalid</span>
                    <span id="code_error" class="errMsg"><%=obj.errMsgs.Code%></span>
				</td></tr>
			<tr class="trField">
				<td class="tdFieldName">Description</td>				    <td class="tdFieldInput">
					<textarea id="description" name="description" rows="5" class="inputTextarea"><%=obj.getDescriptionToString()%></textarea>
				</td>
				<td class="tdErrMsg">
					<span id="description_required" class="errMsg" style="display: none;">Description is required</span>
					<span id="description_invalid" class="errMsg" style="display: none;">Description is invalid</span>
                    <span id="description_error" class="errMsg"><%=obj.errMsgs.Description%></span>
				</td></tr>
			<tr class="trField">
				<td class="tdFieldName">Id Author</td>				<td class="tdFieldInput">
                            <select id="id_author" name="id_author" class="hyjack">
									<%=HtmlUtil.genModelSelect(CacheUtil.getEmployeeList(), null, obj.getIdAuthor())%>
							</select>
				</td>
				<td class="tdErrMsg">
					<span id="id_author_required" class="errMsg" style="display: none;">Id Author is required</span> 
					<span id="id_author_invalid" class="errMsg" style="display: none;">Id Author is invalid</span>
                    <span id="id_author_error" class="errMsg"><%=obj.errMsgs.IdAuthor%></span>
                </td></tr>
			<tr class="trField">
				<td class="tdFieldName">Id Approver</td>				<td class="tdFieldInput">
                            <select id="id_approver" name="id_approver" class="hyjack">
									<%=HtmlUtil.genModelSelect(CacheUtil.getEmployeeList(), null, obj.getIdApprover())%>
							</select>
				</td>
				<td class="tdErrMsg">
					<span id="id_approver_required" class="errMsg" style="display: none;">Id Approver is required</span> 
					<span id="id_approver_invalid" class="errMsg" style="display: none;">Id Approver is invalid</span>
                    <span id="id_approver_error" class="errMsg"><%=obj.errMsgs.IdApprover%></span>
                </td></tr>
			<tr class="trField">
				<td class="tdFieldName">Start Time</td>				<td class="tdFieldInput">
					<table class="tblDateTime">
						<tr class="trDateTime">
							<td class="tdDate">
								<input type="text" maxlength="10" class="inputDate" id="start_time_date" name="start_time_date" value="<%=StringUtil.toDateTimeString(obj.getStartTime())%>" />
								<input type="button" class="btnCalendar" value="..."
									onclick="javascript:displayDatePicker('start_time_date', this, dateFormat);" />
							</td>
							<td class="tdTime">
								<input type="text" maxlength="5" class="inputTime" id="start_time_time" name="start_time_time" value="<%=obj.getStartTime()%>" />
							</td>
						</tr>
					</table></td>
				<td class="tdErrMsg">
                    <span id="start_time_error" class="errMsg"><%=obj.errMsgs.StartTime%></span>
					<div class="divErr">
						<span id="start_time_date_required" class="errMsg"
							style="display: none;">Start Time's date is required</span>
					</div>
					<div class="divErr">
						<span id="start_time_time_required" class="errMsg"
							style="display: none;">Start Time's time is required</span>
					</div>
					<div class="divErr">
						<span id="start_time_date_invalid" class="errMsg"
							style="display: none;">Start Time's date is invalid</span>
					</div>
					<div class="divErr">
						<span id="start_time_time_invalid" class="errMsg"
							style="display: none;">Start Time's time is invalid</span>
					</div>
				</td></tr>
			<tr class="trField">
				<td class="tdFieldName">Id Venue</td>				<td class="tdFieldInput">
                            <select id="id_venue" name="id_venue" class="hyjack">
									<%=HtmlUtil.genModelSelect(CacheUtil.getVenueList(), null, obj.getIdVenue())%>
							</select>
				</td>
				<td class="tdErrMsg">
					<span id="id_venue_required" class="errMsg" style="display: none;">Id Venue is required</span> 
					<span id="id_venue_invalid" class="errMsg" style="display: none;">Id Venue is invalid</span>
                    <span id="id_venue_error" class="errMsg"><%=obj.errMsgs.IdVenue%></span>
                </td></tr>
			<tr class="trField">
				<td class="tdFieldName">Status</td>				<td class="tdFieldInput">
					<select id="status" name="status" class="dropdownlistStyle">
									<%=HtmlUtil.genEnumSelect(EnumName.AgendaStatus, null, obj.getStatus())%>
					</select>
				</td>
				<td class="tdErrMsg">
					<span id="status_required" class="errMsg" style="display: none;">Status is required</span> 
					<span id="status_invalid" class="errMsg" style="display: none;">Status is invalid</span>
                    <span id="status_error" class="errMsg"><%=obj.errMsgs.Status%></span>
                </td></tr>
			<tr class="trField">
				<td class="tdFieldName">Notification</td>				<td class="tdFieldInput">
					<input class="inputInt" type="text" id="notification" name="notification" maxlength="10" value="<%=obj.getNotificationToString()%>" />
				</td>
				<td class="tdErrMsg">
					<span id="notification_required" class="errMsg" style="display: none;">Notification is required</span> 
					<span id="notification_invalid" class="errMsg" style="display: none;">Notification is invalid</span>
                    <span id="notification_error" class="errMsg"><%=obj.errMsgs.Notification%></span>
                </td></tr>
			
			            <tr class="trInputBottom">
				            <td class="tdInputBottom" colspan="3">
					            <table class="tblSubmit" align="center">
						            <tr class="trSubmit">
							            <td class="tdSubmit"><input type="submit" value="Submit" />
							            </td>
							            <td class="tdReset"><input type="reset" value="Reset" /></td>
						            </tr>
					            </table></td>
			            </tr>
		            </table>
	            </form>
            </td>
		</tr>
	</table>
    <br />
	<jsp:include page="agendaList.jsp?embedded=true"></jsp:include>
</body>
</html>